package kr.hkit.framework.inputPanel;

import javax.swing.JTextField;

public class ValidCheck {
	public static void isValidValue(InputTxtPanel p, int length, int intValue) throws Exception{
		JTextField tf = p.getTfValue();
		String str = tf.getText().trim();		
		isValidValue(p,length);
		
		int strInt = Integer.parseInt(str);
		if(strInt > intValue){
			p.getTfValue().requestFocus();
			p.getTfValue().selectAll();
			throw new Exception("범위 초과" + intValue + "이하만 가능");
		}
		
	}
	public static void isValidValue(InputTxtPanel p, int length) throws Exception {
		JTextField tf = p.getTfValue();
		String str = tf.getText().trim();
		
		isValidValue(p);
		
		if (str.length()>length){
			p.getTfValue().requestFocus();
			p.getTfValue().selectAll();
			throw new Exception("자리수 초과" + length + "자리 이하만 가능");
		}
		try{
			Integer.parseInt(str);
		}catch(NumberFormatException e){
			p.getTfValue().requestFocus();
			p.getTfValue().selectAll();
			throw new Exception("정수만 가능");
		}
	}

	public static void isValidValue(InputTxtPanel p) throws Exception {
		String str = p.getTfValue().getText().trim();
		if (str.equals("")){
			p.getTfValue().requestFocus();
			throw new Exception("공백입니다.");
		}
	}
}
